package com.novellotus.iov.carvice.fragment;


import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;

import com.novellotus.iov.carvice.R;
import com.novellotus.iov.carvice.activity.AttentionActivity;
import com.novellotus.iov.carvice.anim.Anim;
import com.novellotus.iov.carvice.anim.AnimCaChu;
import com.novellotus.iov.carvice.anim.EnterAnimLayout;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * A simple {@link Fragment} subclass.
 */
public class EmptyFragment extends BaseFragment {

    @BindView(R.id.anim_layout)
    EnterAnimLayout anim_layout;
    Anim anim;

    public EmptyFragment() {
        // Required empty public constructor
    }


    @Override
    View initRootView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_empty, container, false);
    }

    @Override
    void init() {
        anim_layout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                anim = new AnimCaChu(anim_layout);
                handler.postDelayed(runnable,0);
                anim_layout.getViewTreeObserver().removeOnPreDrawListener(this);
                return false;
            }
        });

    }

    Handler handler = new Handler();
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            //要做的事情
            anim.startAnimation(1500);
            handler.postDelayed(this, 1500);
        }
    };

    @OnClick(R.id.btn_attention)
    void clickAttention() {
        openActivity(getActivity(), AttentionActivity.class);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (handler != null) {
            handler.removeCallbacks(runnable);
            handler = null;
            runnable = null;
        }
    }
}
